package com.zcsy.manage.web.quartz.timer;

import java.util.Timer;
import java.util.TimerTask;

import jxl.common.Logger;
/**
 * java定时任务
 * @Title: OrderTimerTask.java
 * @Package： com.zcsy.manage.web.quartz.time 
 * @author hubing
 * @Copyright: 2016 武汉恒数利通软件有限公司 All rights reserved.
 * @date 2016年8月29日
 * @version 1.0
 * @see JDK1.7.0_75
 * @since
 */
public class OrderTimerTask extends TimerTask{
    
    private Logger logger = Logger.getLogger(OrderTimerTask.class);
    
    public static final int TASK_NO_PAY     = 1; // 未付款
    public static final int TASK_NO_CONFIRM = 2; // 未确认
    public static final int TASK_NO_FINISH  = 3; // 未收货
    
    public static final long DELAY_NO_PAY     = 1000 * 60 * 5;
    public static final long DELAY_NO_CONFIRM = 1000 * 60 * 60 * 24;
    public static final long DELAY_NO_FINISH  = 1000 * 60 * 60 * 24;
    
    /**
     * the delay time, unit: ms
     */
    private long delay;
    private int type;
    private Timer timer;

    /**
     * constructor
     * @param type task type
     * @param timer the timer task
     */
    public OrderTimerTask(int type, Timer timer) {
        super();
        switch (type) {
            case TASK_NO_PAY:
                this.delay = DELAY_NO_PAY;
                break;
            case TASK_NO_CONFIRM:
                this.delay = DELAY_NO_CONFIRM;
                break;
            case TASK_NO_FINISH:
                this.delay = DELAY_NO_FINISH;
                break;
            default:
                break;
        }
        this.type = type;
        this.timer = timer;
    }

    @Override
    public void run() {
        switch (type) {
            case TASK_NO_PAY:
                logger.info("no pay task start...");
                break;
            case TASK_NO_CONFIRM:
                logger.info("no confirm task start...");
                break;
            case TASK_NO_FINISH:
                logger.info("no finish task start...");
                break;
            default:
                break;
        }
        timer.cancel();
    }

    public long getDelay() {
        return delay;
    }

    public void setDelay(long delay) {
        this.delay = delay;
    }
    
    // example
    public static void main(String[] args) {
        Timer timer = new Timer();
        OrderTimerTask task = new OrderTimerTask(OrderTimerTask.TASK_NO_PAY, timer);
        timer.schedule(task, task.getDelay());
    }

}
